﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using seiacpscs_a2.datastructures.linkedlist;

namespace seiacpscs_a2_test.datastructures.linkedList
{
   
    [TestClass]
    public class LinkedListTestCase
    {
        [TestMethod]
        public void testAdd()
        {
            int item1 = 1;
            int item2 = 2;
            int item3 = 3;

            LinkedList list = new LinkedList();
            Assert.AreEqual(0, list.Length);

            list.add(item1);
             Assert.AreEqual(1, list.Length);

            ListNode firstNode = list.First;
            ListNode lastNode = list.Last;

            Assert.AreEqual(1, firstNode.Item);
            Assert.AreEqual(1, lastNode.Item);

            list.add(item2);
             Assert.AreEqual(2, list.Length);

            ListNode firstNode2 = list.First;
            ListNode lastNode2 = list.Last;

             Assert.AreEqual(1, firstNode2.Item);
             Assert.AreEqual(2, lastNode2.Item);


            list.add(item3);
             Assert.AreEqual(3, list.Length);

            ListNode firstNode3 = list.First;
            ListNode lastNode3 = list.Last;

             Assert.AreEqual(1, firstNode3.Item);
             Assert.AreEqual(3, lastNode3.Item);

        }
	 
    [TestMethod]
	public void testContains(){
	
		 int item1 = 1;
		 int item2 = 2;
		 int item3 = 3;
		 
		 LinkedList list = new LinkedList();
		  Assert.AreEqual(0, list.Length);
			
	     list.add(item1);
		  Assert.AreEqual(1, list.Length);
		 
		 list.add(item2);
		  Assert.AreEqual(2, list.Length);
		 
		 list.add(item3);
		  Assert.AreEqual(3, list.Length);
		 
		 Assert.IsTrue(list.contains(item1));
		  Assert.AreEqual(1,list.NumberOfAccesses);
		 
		 Assert.IsTrue(list.contains(item2));
		  Assert.AreEqual(2,list.NumberOfAccesses);

          Assert.IsTrue(list.contains(item3));
		  Assert.AreEqual(3,list.NumberOfAccesses);

          Assert.IsFalse(list.contains(4));
		  Assert.AreEqual(3,list.NumberOfAccesses);
	}

    [TestMethod]
	public  void testContainsWithEmptyList()
	{
		
		LinkedList list = new LinkedList();
		
		Assert.AreEqual(0, list.Length);
		Assert.IsFalse(list.contains(1));
	
		
	}
	
    [TestMethod]
	public void testGetItemAt(){
		int item0 = 0;
		 int item1 = 1;
		 int item2 = 2;
		 
		 LinkedList list = new LinkedList();
		 Assert.AreEqual(0, list.Length);
			
	     list.add(item0);
		 Assert.AreEqual(1, list.Length);
		 
		 list.add(item1);
		 Assert.AreEqual(2, list.Length);
		 
		 list.add(item2);
		 Assert.AreEqual(3, list.Length);
		 
		 Assert.AreEqual(item0,list.getItemAt(0));
		 Assert.AreEqual(item1,list.getItemAt(1));
		 Assert.AreEqual(item2,list.getItemAt(2));
	}

    }
}
